package com.li.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.li.bean.Student;
import com.li.common.Dbutil;
import com.li.dao.StudentDao;

public class StudentDaoImpl implements StudentDao{
	private Connection conn = null;
	private PreparedStatement pst = null;
	private ResultSet rs = null;
	private Dbutil db = new Dbutil();
	
	@Override
	public List<Student> selectAll() {
		String sql="select * from li_v_stu"; 
		List<Student> list = new ArrayList<Student>();
		
		try {
			conn = db.getConn();
			pst  = conn.prepareStatement(sql);
			rs   = pst.executeQuery();
			while(rs.next()){
				Student stu = new Student();
				stu.setId(rs.getInt("id"));
				stu.setName(rs.getString("name"));
				stu.setAge(rs.getInt("age"));
				stu.setSex(rs.getString("sex"));
				stu.setProvincename(rs.getString("provincename"));
				stu.setClassname(rs.getString("classname"));
				stu.setGitname(rs.getString("gitname"));
				list.add(stu);
			}
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			db.closeAll();
		}
		
		return list;
	}
	
	

}
